<?php
    class StatsAnalyzer
    {
        private $keys_ = array();
        private $keyWords_ = array();
        private $date_;

        function construct_($keyWords, $date)
        {
            $this->keyWords_ = $keyWords;
            $this->date_ = $date;
        }

        public function readXML($path)
        {
            //initializeVector();
            DateTime dateTime = Convert.ToDateTime(date_);

            XmlDocument doc = new XmlDocument();
            doc.Load(path);

            XmlNodeList advertisementList = doc.GetElementsByTagName("Advertisement");

            foreach (XmlNode node in advertisementList)
            {
                XmlElement advertiseElement = (XmlElement)node;
                string xmlDate = advertiseElement.GetElementsByTagName("Date")[0].InnerText;

                DateTime dating = convertDate(xmlDate);
                if (dateTime <= dating)
                {
                    string xmlAdvertisementLink = advertiseElement.GetElementsByTagName("AdvertisementLink")[0].InnerText;
                    checkKeyWords(xmlAdvertisementLink);
                }
            }
            TextWriter tw = new StreamWriter("yeah.txt");
            for (int i = 0; i < keyWords_.Count; i++)
            {
                tw.WriteLine(keyWords_[i] +" "+ keys_[i]);
            }
            tw.Close();
        }

        private void checkKeyWords(string advText)
        {
            CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo;
            for (int i = 0; i < keyWords_.Count; i++)
            {
                int positionOfMysql = Compare.IndexOf(advText, keyWords_[i].ToString(), CompareOptions.IgnoreCase);
                if (positionOfMysql != -1)
                {
                    keys_[i] = keys_[i] + 1;
                }
            }
        }

        void initializeVector()
        { 
            for (int i = 0; i < keyWords_.Count; i++) 
            {
                keys_.Add(0);
            }
        }

        DateTime convertDate(string date)
        {
            string datel;
            DateTime dateTime = new DateTime(1/1/1);
            try
            {
                string[] words = date.Split('/');
                datel = words[1] + " " + words[0] + " " + words[2];          
                dateTime = Convert.ToDateTime(datel);              
            }
            catch (Exception ex)
            { }
            return dateTime;
        }     
    }
}
